package cn.sunline.dreamvalue.config;

import cn.sunline.dreamvalue.constant.CommonResult;
import cn.sunline.dreamvalue.constant.ResultStatus;
import cn.sunline.dreamvalue.exception.DreamValueExcption;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author zjp
 * @title: ExceptionAdvance
 * @projectName dream-value
 * @description: 梦想值controller
 * @date 2020/5/12 14:15
 */
@ControllerAdvice
@Slf4j
public class ExceptionAdvance {


    /**
    　* @description: TODO
    　* @param
    　* @return 
    　* @author zjp
    　* @date 2020/5/12 14:20 
    */
    @ResponseBody
    @ExceptionHandler(value = Exception.class)
    public CommonResult errorHandler(Exception e, HttpServletRequest request){
        log.error("[产生系统异常] url:{}", request.getRequestURI(), e);
        if (e instanceof DreamValueExcption){
            DreamValueExcption exception = (DreamValueExcption) e;
            return CommonResult.exceptionResult(exception.getResultStatus());
        }
        return CommonResult.exceptionResult(ResultStatus.SYS_INNER_EXCEPTION);
    }
}
